package bb.lanxing.lib.widget.indicator;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.OvershootInterpolator;

public class DotView extends View {
    private Point footPoint;
    private Point headPoint;
    private Paint paint;
    private Path path;

    public DotView(Context context) {
        this(context, null);
    }

    public DotView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public DotView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        init();
    }

    private void init() {
        setAlpha(0.0f);
        this.headPoint = new Point();
        this.footPoint = new Point();
        this.path = new Path();
        Paint paint = new Paint();
        this.paint = paint;
        paint.setAntiAlias(true);
        this.paint.setStyle(Paint.Style.FILL_AND_STROKE);
        this.paint.setStrokeWidth(1.0f);
    }

    private void makePath() {
        float radius = (float) (this.headPoint.getRadius() * Math.sin(Math.atan((this.footPoint.getY() - this.headPoint.getY()) / (this.footPoint.getX() - this.headPoint.getX()))));
        float radius2 = (float) (this.headPoint.getRadius() * Math.cos(Math.atan((this.footPoint.getY() - this.headPoint.getY()) / (this.footPoint.getX() - this.headPoint.getX()))));
        float radius3 = (float) (this.footPoint.getRadius() * Math.sin(Math.atan((this.footPoint.getY() - this.headPoint.getY()) / (this.footPoint.getX() - this.headPoint.getX()))));
        float radius4 = (float) (this.footPoint.getRadius() * Math.cos(Math.atan((this.footPoint.getY() - this.headPoint.getY()) / (this.footPoint.getX() - this.headPoint.getX()))));
        float x = this.headPoint.getX() - radius;
        float y = this.headPoint.getY() + radius2;
        float x2 = this.headPoint.getX() + radius;
        float y2 = this.headPoint.getY() - radius2;
        float x3 = this.footPoint.getX() - radius3;
        float y3 = this.footPoint.getY() + radius4;
        float x4 = this.footPoint.getX() + radius3;
        float y4 = this.footPoint.getY() - radius4;
        float x5 = (this.footPoint.getX() + this.headPoint.getX()) / 2.0f;
        float y5 = (this.footPoint.getY() + this.headPoint.getY()) / 2.0f;
        this.path.reset();
        this.path.moveTo(x, y);
        this.path.quadTo(x5, y5, x3, y3);
        this.path.lineTo(x4, y4);
        this.path.quadTo(x5, y5, x2, y2);
        this.path.lineTo(x, y);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        makePath();
        canvas.drawPath(this.path, this.paint);
        canvas.drawCircle(this.headPoint.getX(), this.headPoint.getY(), this.headPoint.getRadius(), this.paint);
        canvas.drawCircle(this.footPoint.getX(), this.footPoint.getY(), this.footPoint.getRadius(), this.paint);
        super.onDraw(canvas);
    }

    public void animCreate() {
        setPivotX(getHeadPoint().getX());
        setPivotY(getFootPoint().getY());
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(this, "scaleX", 0.3f, 1.0f);
        ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(this, "scaleY", 0.3f, 1.0f);
        animatorSet.play(ofFloat).with(ofFloat2).with(ObjectAnimator.ofFloat(this, "alpha", 0.0f, 1.0f));
        animatorSet.setDuration(500L);
        animatorSet.setInterpolator(new OvershootInterpolator());
        animatorSet.setStartDelay(300L);
        animatorSet.start();
    }

    public Point getHeadPoint() {
        return this.headPoint;
    }

    public Point getFootPoint() {
        return this.footPoint;
    }

    public void setIndicatorColor(int i) {
        this.paint.setColor(i);
    }

    public int getIndicatorColor() {
        return this.paint.getColor();
    }
}
